<template>
	<view class="h-[calc(100vh-45px)] py-1 px-3 flex flex-col justify-between">
		<!-- 打包装车 -->
		<view>
			<uv-form labelPosition="left" labelWidth="auto" :model="formModel">
				<uv-form-item label="车辆编号" prop="delivery.carNo" borderBottom>
					<uv-input v-model="formModel.delivery.carNo" border="none" placeholder="请输入车辆编号" />
				</uv-form-item>
				<uv-form-item label="清关单号" prop="delivery.transferOrderNumber">
					<uv-input v-model="formModel.delivery.transferOrderNumber" border="none" placeholder="请输入或扫描清关单号" />
					<uni-icons type="scan" size="20" @click="getOrder" />
				</uv-form-item>
			</uv-form>
			<uni-table border stripe emptyText="暂无更多数据" class="mt-2">
				<!-- 表头行 -->
				<uni-tr>
					<uni-th align="center">快递单号</uni-th>
					<uni-th align="center">快递名</uni-th>
					<uni-th align="center">快递类型</uni-th>
					<uni-th align="center">会员id</uni-th>
					<uni-th align="center">会员名称</uni-th>
					<uni-th align="center">订单号</uni-th>
					<uni-th align="center">重量</uni-th>
					<uni-th align="center">存放区域</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-th align="center">{{ item.domesticDeliveryNo }}</uni-th>
					<uni-th align="center">{{ item.cargoName }}</uni-th>
					<uni-th align="center">{{ item.cargoType }}</uni-th>
					<uni-th align="center">{{ item.userId }}</uni-th>
					<uni-th align="center">{{ item.userName }}</uni-th>
					<uni-th align="center">{{ item.orderNo }}</uni-th>
					<uni-th align="center">{{ item.weight }}</uni-th>
					<uni-th align="center">{{ item.seat }}</uni-th>					
				</uni-tr>
			</uni-table>
		</view>
		<view>
			<uv-button type="primary" shape="circle" @click="setPackTruck">打包装车</uv-button>
		</view>
	</view>
</template>

<script setup>
	import { getPackTruckApi, setPackTruckApi } from '@/api/modules/packignTruck.js'
	
	const formModel = ref({
		delivery: {
			carNo: '', // 车辆编号
			transferOrderNumber: '' // 清关单号 / 面单号
		}
	}) // 查询条件
	const tableData = ref([]) // 表格数据
	
	 // 获取订单详情 1009611
	const getOrder = async () => {
		const res = await getPackTruckApi({ transferOrderNumber: formModel.value.delivery.transferOrderNumber })
		if(res.data) {
			tableData.value.push(res.data)
		}
		console.log(res)
	}
	
	// 绑定车辆与订单 打包装车
	const setPackTruck = () => {
		if(tableData.value.length > 0) {
			setPackTruckApi(formModel.value.delivery).then(res => {
				if(res.code === 200) {
					uni.showToast({ title: '成功打包装车' })
					setTimeout(() => {
						uni.navigateBack({ delta: 1, animationType: 'pop-out' })
					}, 1000)
				}
			})
		}
	}
</script>

<style>

</style>
